package com.example.view;

import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Rect;
import android.graphics.RectF;
import android.util.AttributeSet;
import android.view.View;

public class MyView extends View {
    private Paint mPaint = new Paint();//创建一个画笔

    public MyView(Context context) {
        super(context);
        initPaint();
    }

    public MyView(Context context, AttributeSet attrs) {
        super(context, attrs);
        initPaint();
    }

    //初始化画笔
    private void initPaint() {
        mPaint.setColor(Color.BLUE);//设置画笔颜色
        mPaint.setStyle(Paint.Style.STROKE);//设置画笔模式为填充
        mPaint.setStrokeWidth(10f);//设置画笔宽度为10px
    }

    @SuppressLint("DrawAllocation")
    @Override
    protected void onDraw(Canvas canvas) {
//        super.onDraw(canvas);
        //绘制点
//        canvas.drawPoint(200, 200, mPaint);
//        canvas.drawPoints(new float[]{
//                500, 500,
//                500, 600,
//                500, 700}, mPaint);
        //绘制线
//        canvas.drawLine(300,300,500,600,mPaint);
//        canvas.drawLines(new float[]{
//                100,200,200,200,
//                100,300,200,300
//        },mPaint);
//        //绘制矩形
//        mPaint.setColor(Color.GRAY);//设置画笔颜色
//        canvas.drawRect(100,100,800,400,mPaint);
//        //绘制圆角矩形
//        RectF rectF=new RectF(100,100,800,400);
//        mPaint.setColor(Color.BLUE);
//        canvas.drawRoundRect(rectF,350,150,mPaint);
        //绘制椭圆
//        RectF rectF = new RectF(100,100,800,400);
//        canvas.drawOval(rectF,mPaint);
        //绘制圆
//        canvas.drawCircle(500,500,400,mPaint);
        //绘制圆弧
        mPaint.setColor(Color.GRAY);//设置画笔颜色
        RectF rectF = new RectF(100, 100, 800, 400);
        canvas.drawRect(rectF, mPaint);
        mPaint.setColor(Color.BLUE);
        canvas.drawArc(rectF, 0, 90, false, mPaint);
    }
}
